<%@page pageEncoding="utf-8" %>

<script>
    $(function () {
        $('#myGuruTable').datagrid({
            url:"${pageContext.request.contextPath}/guru/selectGuru",
            pagination:true,

            columns:[[
                {field:'guruId',title:'编号'},
                {field:'guruName',title:'上师姓名'},
                {title:'上师头像',field:'guruImage',
                    formatter:function (value,rowdata,index) {
                        return "<img src='${pageContext.request.contextPath }/img/"+value+"' style=width:30px;height:30px;>"
                    }
                },

                {field:'guruNickName',title:'上师法号'},
                {field:'guruStatus',title:'上师状态',
                    formatter:function (value,rowdata,index) {
                        if(value==0){
                            return "正常";
                        }else {
                            return "删除";
                        }
                    }
                },
            ]]
        });
    })
    //点击按钮出现添加窗口
    function tianjiaguru() {
        $('#myGuruDiv').dialog("open");
    }
    $(function () {
        $('#myGuruDiv').dialog({
            title: '添加信息',
            width: 400,
            height: 200,
            closed: true,
            modal: true
        });
    })
    //搜索
    function gurnss() {
        var sguruName = $("#sguruName").val();
        $('#myGuruTable').datagrid('load',{
            "sguruName":sguruName
        });
    }
    //excel上传
    function gurnsc() {
        $('#guruscform').form('submit', {
            url:"${pageContext.request.contextPath}/guru/daoru",
            onSubmit: function(){
                // do some check
                // return false to prevent submit;
            },
            success:function(data){
                alert(data)
            }
        })
    }
    
    //添加数据
    function tijiaoguru() {
        alert("aaaa");
        $('#myGuruForm').form('submit', {
            url:"${pageContext.request.contextPath}/guru/insertGuru",
            onSubmit: function(){
            // do some check
            // return false to prevent submit;
            },
            success:function(data){
                var data1 = JSON.parse(data);
                alert(data1.guruinsert)
                if(data1.guruinsert){
                    alert("添加成功");
                    $('#myGuruTable').datagrid('reload');
                    $('#myGuruDiv').dialog("close");
                }else {
                    alert("添加失败");
                }
            }
        });
    }


    







</script>
<a id="btn" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="tianjiaguru()">添加</a>
<input type="text" id="sguruName">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="gurnss()">点击搜索</a>

<form id="guruscform" method="post" enctype="multipart/form-data">
    <input type="file" name="excel" size="1">

</form>

<a href="javascript:void(0)" class="easyui-linkbutton" onclick="gurnsc()">点击上传</a>
<a href="${pageContext.request.contextPath}/guru/daochu" class="easyui-linkbutton" onclick="gurnxz()">点击下载</a>

<table id="myGuruTable"></table>


<%--添加上师--%>
<div id="myGuruDiv">
    <form id="myGuruForm" method="post" enctype="multipart/form-data">
        上师姓名<input type="text" name="guruName"><br/>
        上师头像<input type="file"  name="touxiang"><br/>
        上师法号<input type="text"  name="guruNickName"><br/>
        <input type="button" value="提交" onclick="tijiaoguru()">
    </form>

</div>


